/**
 * Created with IntelliJ IDEA.
 * User: duoba
 * Date: 16/2/25
 * Time: 下午4:37
 * To change this template use File | Settings | File Templates.
 */

package com.cake21.uitest.Case;

import com.cake21.uitest.Page.CakeListPage;
import com.cake21.uitest.Page.CakePage;
import com.cake21.uitest.Page.CheckOutPage;
import com.cake21.uitest.Page.IndexPage;
import com.cake21.uitest.Page.LoginPage;
import com.cake21.uitest.System.Core.Case;
import com.cake21.uitest.System.Core.Utils;

/* 登陆,选购,下单 Case */
public class CakeUITest extends Case {
    @Override
    protected void execute() {
        /*21 Cake 主页*/
        IndexPage index = new IndexPage();
        /*主页截图*/
        judge.pass("21Cake主页截图", screenshot());
        /*确认弹出窗口*/
        index.confirmPopUpBtn();
        /*登陆页面*/
        LoginPage login = index.goLogin();
        judge.info(login.getPageTitle(), "用户登录页面Title");
        judge.is(login.getPageTitle().contains("用户登录"), "验证用户登录页面Title");
        /*输入用户名*/
        login.enterUser();
        /*输入密码*/
        login.enterPwd();
        /*登陆页面截图*/
        judge.pass("21Cake登陆页面截图", screenshot());
        /*点击登陆*/
        login.pressLoginBtn();
        /*蛋糕列表页*/
        CakeListPage cakeList = new CakeListPage();
        /*蛋糕列表页截图*/
        judge.pass("21cake蛋糕列表页截图", screenshot());
        /*蛋糕列表页判断蛋糕数量*/
        judge.is(cakeList.getGoodsCount() > 1, "蛋糕数量是否大于1", "蛋糕实际数量: " + cakeList.getGoodsCount());
        /*蛋糕详情页*/
        CakePage cakeDetail = cakeList.goCakeDetail();
        /*切换浏览器Windows*/
        Utils.switchToWindow(cakeDetail.getDriver(), cakeDetail.getPageTitle());
        /*蛋糕详情页截图*/
        judge.pass("21Cake蛋糕详情页截图", screenshot(cakeDetail.getDriver()));
        /*验证切换浏览器*/
        judge.is(cakeDetail.getDriver() != null, "验证切换浏览器窗口是否正确");
        /*下单页面*/
        CheckOutPage cOut = cakeDetail.goCheckOut();
        /*验证下单页面是否存在,因为有"到货通知"的时候*/
        judge.is(cOut != null, "下单页面是否存在");
        if(cOut != null) {
            /*选择配送时间*/
            cOut.selectShipTime();
            /*验证下单时间*/
            judge.is(!cOut.getShipTime().equals(""), "验证下单时间", "返回下单时间为: " + cOut.getShipTime());
            /*下单页面截图*/
            judge.pass("21Cake下单页面截图", screenshot(cOut.getDriver()));

            /*不要点击提交*/
            //cOut.goSubmitOrder();
        }
    }
}